<?php $this->Html->LoadCss("main"); ?>
<div id="tenap-main" class="shadow">   
    
    <div id="sesq"></div>
    <div id="plan"></div>
    
    <div id="box-container">
        <div id="box1aux"></div>
        <div id="box2aux"></div>
        <div id="box3aux"></div>
        <div id="box4aux"></div>
        <div id="box5aux"></div>
    
        <?php 
            $total = count($destaques);
            $dest1 = $dest2 = array();
            $i = 0;
            while($total > 0){
                if($total >= 2){
                    $total -= 2;
                    $dest1[] = array_shift($destaques);
                    $dest2[] = array_shift($destaques);
                }elseif($total == 1){
                    $total -= 1;
                    $dest1[] = array_shift($destaques);
                }
            }            

            function pag_ini($slider, $imagens, $conteudo_id, $item_id, $url, $id, $img_size = "min"){
                $slider->setUrlController($url);
                $slider->setConteudoID($conteudo_id);
                $slider->setItemID($item_id);
                $slider->drawArtigo($imagens, $id, '', $img_size);
            }

            $this->LoadJsPlugin('slider/easyslider', 'slider');
            pag_ini($this->slider, $imagens  , 'catnome', 'cod_categoria', "tenap/segmento/show/", "box4", 'max');
            pag_ini($this->slider, $novidades, 'titulo' , 'cod_novidade' , "blog/novidades/show/", "box3");
            pag_ini($this->slider, $dest2    , 'titulo' , 'cod_artigo'   , "blog/artigo/show/"   , "box2");
            pag_ini($this->slider, $dest1    , 'titulo' , 'cod_artigo'   , "blog/artigo/show/"   , "box1");

        ?>
    </div>
</div>

<?php

    function tenap_drawbox($id, $delay){
        static $time       = 2000;
        static $desaparece = 2000;
        $delay            += 600;
        $speed             = 2000;
        $tempo_espera      = 2000;
        $show_time         = 800;
        $fadeintime        = $show_time + $tempo_espera;
        
        $time+= $speed;
        $desaparece -= $fadeintime;
        $desaparece += $tempo_espera;
        $var = " 
            $('#$id').easySlider({
                auto: true,
                continuous: true,
                nextText: '',
                numeric: false,
                pause: $time,
                prevText: '',
                speed: $speed
            });
        ";
        
        //unset($_SESSION['entrada']);
        if(!isset($_SESSION['entrada'])){
            $var = "
            $('#$id'+'aux').delay($delay).fadeIn($fadeintime).delay($desaparece).fadeOut($show_time, function() {
                $('#$id').show($show_time, function() { $var }); });";
            //$var = "$('#$id'+'aux').fadeIn($fadeintime);";
        }else $var = "$('#$id').fadeIn(1, function() { $var });";
        
        return $var;
        
    }
    
    $slider  = "";
    $slider .= tenap_drawbox("box5", "1200");
    $slider .= tenap_drawbox("box4", "1600");
    $slider .= tenap_drawbox("box3", "2000");
    $slider .= tenap_drawbox("box2", "2400");
    $slider .= tenap_drawbox("box1", "2800");
    $this->Html->LoadJqueryFunction($slider);
    
    if(!isset($_SESSION['entrada'])) $_SESSION['entrada'] = true;

?>